home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / SMTPCEMS.ZIP / PARAM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-15  |  3.6 KB  |  123 lines

  1. /* param.c [edit EMAIL.H before compiling] */
  2.  
  3. #include <windows.h>
  4. #include "param.h"
  5. #include "message.h"
  6. #include "paint.h"
  7. #include "see.h"
  8. #include "email.h"
  9.  
  10. #define MAX_BUF 1024
  11. #define MAX_STR   80
  12.  
  13. static char Temp[MAX_STR+8]  = "\0";
  14. static char Server[MAX_STR+1] = SMTP_HOST_NAME;
  15. static char From[MAX_STR+1]   = YOUR_EMAIL_ADDR;
  16. static char To[MAX_STR+1]     = "\0";
  17. static char Subj[MAX_STR+1]   = "\0";
  18. static char Message[MAX_BUF+1]= "\0";
  19.  
  20. void DisplayError(int Code)
  21. {static char ErrorMsg[MAX_STR+1];
  22.  seeErrorText(Code,(LPSTR)ErrorMsg,MAX_STR);
  23.  wsprintf((LPSTR)Temp,"SEE Error %d: %s", Code, (LPSTR)ErrorMsg);
  24.  DisplayLine((LPSTR)Temp);
  25. }
  26.  
  27. #ifdef WIN32
  28. BOOL CALLBACK
  29. #else
  30. BOOL FAR PASCAL
  31. #endif
  32. ParamDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
  33. {int n;
  34.  int Code;
  35.  
  36.  switch (iMsg)
  37.     {
  38.      case WM_INITDIALOG:
  39.          return TRUE;
  40.  
  41.      case WM_COMMAND:
  42.      
  43.          if(wParam==IDOK)
  44.            {//EndDialog(hDlg, TRUE);
  45.             return TRUE;
  46.            } 
  47.          if(wParam==IDCANCEL)
  48.            {EndDialog(hDlg, TRUE);
  49.             return TRUE;
  50.            } 
  51.          if(wParam==MSG_QUIT)
  52.            {EndDialog(hDlg, TRUE);
  53.             return TRUE;
  54.            }           
  55.          if(wParam==MSG_SENDMAIL)
  56.            {
  57.             n = GetDlgItemText(hDlg, DB_SUBJ, (LPSTR)Subj, MAX_STR);
  58.             Subj[n] = '\0';
  59.             n = GetDlgItemText(hDlg, DB_TO,  (LPSTR)To,  MAX_STR);
  60.             To[n] = '\0';
  61.             n = GetDlgItemText(hDlg, DB_MSG, (LPSTR)Message, MAX_BUF);
  62.             Message[n] = '\0';
  63.  
  64.             {static char Temp[MAX_BUF+1];
  65.             
  66.              wsprintf((LPSTR)Temp,"Server = [%s]", (LPSTR)Server);
  67.              DisplayLine((LPSTR)Temp);
  68.              wsprintf((LPSTR)Temp,"From = [%s]", (LPSTR)From);
  69.              DisplayLine((LPSTR)Temp);                       
  70. #if 1            
  71.              wsprintf((LPSTR)Temp,"Subj = [%s]", (LPSTR)Subj);
  72.              DisplayLine((LPSTR)Temp);
  73.              wsprintf((LPSTR)Temp,"To = [%s]", (LPSTR)To);
  74.              DisplayLine((LPSTR)Temp);
  75.              wsprintf((LPSTR)Temp,"Message = [%s]", (LPSTR)Message);
  76.              DisplayLine((LPSTR)Temp);
  77. #endif             
  78.             }
  79.               
  80.             /* check address */
  81.             Code = seeVerifyFormat((LPSTR)To);           
  82.             if(Code<0) 
  83.               {DisplayError(Code); 
  84.                break;
  85.               }  
  86.               
  87.             seeStringParam(SEE_LOG_FILE, (LPSTR)"quick.log"); /*!!!*/
  88.             
  89.             /* connect to SMTP server */
  90.             DisplayLine("Connecting...");
  91.             Code = seeSmtpConnect(
  92.                 (LPSTR)Server,
  93.                 (LPSTR)From, 
  94.                 (LPSTR)NULL);
  95.             if(Code<0) 
  96.                {DisplayError(Code); 
  97.                 break;
  98.                }
  99.             /* send email */
  100.             DisplayLine("Sending mail...");
  101.             Code = seeSendEmail(
  102.                 (LPSTR)To,
  103.                 (LPSTR)NULL,              /* no CC list */
  104.                 (LPSTR)NULL,              /* no BCC list */
  105.                 (LPSTR)Subj,
  106.                 (LPSTR)Message,
  107.                 (LPSTR)NULL);             /* no attachments */                
  108.             if(Code<0)
  109.                {DisplayError(Code); 
  110.                 break;
  111.                }              
  112.             DisplayLine("Closing...");
  113.             DisplayLine("Email has been sent.");
  114.             seeClose();              
  115.             EndDialog(hDlg, TRUE);
  116.             return TRUE;
  117.            }
  118.      break;
  119.     }
  120.   return FALSE;
  121. } /* end ParamDlgProc */
  122.                        
  123.